#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "SimpleLight.h"
#include "mock/LoggerMock.h"
#include "mock/ArduinoMock.h"
#include "mock/MessageRouterMock.h"
using ::testing::Return;
using ::testing::Eq;
using ::testing::ByRef;

class SimpleLightTest : public ::testing::Test {
public:
	SimpleLightTest() : simpleLight(arduino, router, "test", log, "kitchen", "kitchen") {}
protected:
	ArduinoMock arduino;
	MessageRouterMock router;
	SimpleLight simpleLight;
	LoggerMock log;
	
	virtual void SetUp() {
		EXPECT_CALL(router, addService(Eq(ByRef(simpleLight))));
		router.addService(simpleLight);
	}
};

TEST_F(SimpleLightTest, turnOnOffWhenButtonPressed){
	EXPECT_CALL(router, postMessage(_, String("{\"cmd\":\"light\", \"id\":\"kitchen\", \"state\":\"on\"}")))
		.Times(1);
	simpleLight.onMessage("{\"event\":\"button\", \"id\":\"kitchen\", \"state\":\"on\"}");
	EXPECT_CALL(router, postMessage(_, String("{\"cmd\":\"light\", \"id\":\"kitchen\", \"state\":\"off\"}")))
		.Times(1);
	simpleLight.onMessage("{\"event\":\"button\", \"id\":\"kitchen\", \"state\":\"on\"}");
}





